Location: pH control @ 2653eaa51ed0 / pH Homeostasis.nb

Author:
Randall Britten <r.britten@auckland.ac.nz>
Date:
2013-12-02 11:55:34+13:00
Desc:
Manipulate now shows ODE results allowing for initial pH and initial CO2 level to be adjusted.
Permanent Source URI:
https://models.physiomeproject.org/workspace/178/rawfile/2653eaa51ed0bd5e017f09c9ab5eb6ef244c691e/pH Homeostasis.nb

(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 9.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[     15170,        393]
NotebookOptionsPosition[     14153,        359]
NotebookOutlinePosition[     14508,        375]
CellTagsIndexPosition[     14465,        372]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 RowBox[{
  RowBox[{"initialPh", "=", "7.4"}], ";"}]], "Input",
 CellChangeTimes->{{3.588028935288416*^9, 3.588028947630732*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"Hmolar", "[", "initialPh_", "]"}], ":=", 
   SuperscriptBox["10", 
    RowBox[{"-", "initialPh"}]]}], ";"}]], "Input",
 CellChangeTimes->{
  3.588026866945672*^9, 3.588027345006266*^9, {3.588027526578341*^9, 
   3.588027528457705*^9}, {3.5880275950477552`*^9, 3.588027623943098*^9}, {
   3.588028951319806*^9, 3.588028955827985*^9}, {3.588029035381466*^9, 
   3.5880290360526953`*^9}, {3.594926481999916*^9, 3.594926490448428*^9}, 
   3.594926838297065*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialCO2mmHg", "=", "40"}], ";"}]], "Input",
 CellChangeTimes->{{3.588028961701105*^9, 3.5880289701902637`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"solubilityMolarPerMmhg", "=", "0.03"}], ";"}]], "Input",
 CellChangeTimes->{{3.588011381426174*^9, 3.5880113944215317`*^9}, {
  3.588029074748098*^9, 3.588029092014204*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"CO2molar", "[", "CO2mmHg_", "]"}], ":=", 
   FractionBox[
    RowBox[{"CO2mmHg", " ", "solubilityMolarPerMmhg"}], "1000"]}], 
  ";"}]], "Input",
 CellChangeTimes->{
  3.588026852226532*^9, 3.588026943288953*^9, {3.5880275452983923`*^9, 
   3.58802754682507*^9}, {3.588027627063496*^9, 3.588027635999963*^9}, {
   3.588028977886209*^9, 3.588029022197158*^9}, {3.588030010813973*^9, 
   3.5880300116060743`*^9}, {3.588032567434842*^9, 3.58803257466298*^9}, {
   3.594926783617146*^9, 3.5949268167756987`*^9}, 3.594926850790475*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"pKfromTextbook", "=", "6.1"}], ";"}]], "Input",
 CellChangeTimes->{{3.588028556376622*^9, 3.58802856809615*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"KfromTextbook", "=", 
   SuperscriptBox["10", 
    RowBox[{"-", "pKfromTextbook"}]]}], ";"}]], "Input",
 CellChangeTimes->{{3.588012103263454*^9, 3.588012122807251*^9}, 
   3.588012563011053*^9, 3.588029064612894*^9, {3.5880300336289062`*^9, 
   3.588030043062311*^9}, 3.588033492664633*^9, 3.588034881261235*^9}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialCO2molar", "=", 
   RowBox[{"CO2molar", "[", "initialCO2mmHg", "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.5949268814060183`*^9, 3.5949268954061327`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialHCO3molar", "=", 
   RowBox[{"initialCO2molar", " ", 
    FractionBox["KfromTextbook", 
     SuperscriptBox["10", 
      RowBox[{"-", "initialPh"}]]]}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588035465787499*^9, 3.588035507516808*^9}, {
  3.588035570662325*^9, 3.588035584396131*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"pCO2", "[", 
    RowBox[{"pH_", ",", "HCO3_", ",", "K_"}], "]"}], ":=", 
   RowBox[{
    FractionBox[
     SuperscriptBox["10", 
      RowBox[{"-", "pH"}]], "K"], 
    FractionBox["HCO3", "solubilityMolarPerMmhg"]}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588011527879652*^9, 3.588011574290142*^9}, {
  3.588011605456628*^9, 3.588011648639924*^9}, {3.5880119395225277`*^9, 
  3.588011941657003*^9}, {3.588029099237656*^9, 3.588029102004583*^9}, {
  3.588029742140643*^9, 3.588029745588648*^9}, {3.5880298638730307`*^9, 
  3.588029870777545*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"initialHmolar", "=", 
   RowBox[{"Hmolar", "[", "initialPh", "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.594926909677643*^9, 3.594926920275756*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"KbyInitial", "=", 
   FractionBox[
    RowBox[{"initialHmolar", " ", "initialHCO3molar"}], "initialCO2molar"]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.5880276531793737`*^9, 3.5880276717256613`*^9}, {
   3.588027720485572*^9, 3.588027766262341*^9}, 3.588028516161331*^9, {
   3.588029040884555*^9, 3.5880290519690933`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"pKbyInitial", " ", "=", " ", 
   RowBox[{"-", 
    RowBox[{"Log10", "[", "KbyInitial", "]"}]}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588027774043713*^9, 3.588027798668395*^9}, 
   3.588028524865922*^9}],

Cell[BoxData[
 RowBox[{"ContourPlot", "[", 
  RowBox[{
   RowBox[{"pCO2", "[", 
    RowBox[{"pH", ",", "HCO3", ",", "KfromTextbook"}], "]"}], ",", 
   RowBox[{"{", 
    RowBox[{"pH", ",", "6.8", ",", "8"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"HCO3", ",", "0", ",", "100"}], "}"}], ",", "\[IndentingNewLine]", 
   RowBox[{"Contours", "\[Rule]", 
    RowBox[{"{", 
     RowBox[{"20", ",", "40", ",", "80"}], "}"}]}]}], "\[IndentingNewLine]", 
  "]"}]], "Input",
 CellChangeTimes->{{3.588011703454999*^9, 3.5880117174087048`*^9}, {
  3.5880117501903267`*^9, 3.588011883386302*^9}, {3.588012489020569*^9, 
  3.588012525930511*^9}, {3.58802796882439*^9, 3.5880279848488283`*^9}, {
  3.5880303452699127`*^9, 3.588030350357877*^9}, {3.5880322855350943`*^9, 
  3.5880322876371603`*^9}, {3.5880324327627296`*^9, 3.588032437474824*^9}, {
  3.588033246047154*^9, 3.5880332502935057`*^9}}],

Cell[BoxData[
 RowBox[{"Plot3D", "[", 
  RowBox[{
   RowBox[{"pCO2", "[", 
    RowBox[{"pH", ",", "HCO3", ",", "KfromTextbook"}], "]"}], ",", 
   RowBox[{"{", 
    RowBox[{"pH", ",", "6.8", ",", "8"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"HCO3", ",", "0", ",", "100"}], "}"}], ",", "\[IndentingNewLine]", 
   RowBox[{"Mesh", "\[Rule]", "None"}], ",", "\[IndentingNewLine]", 
   RowBox[{"ColorFunction", "\[Rule]", "Hue"}]}], "\[IndentingNewLine]", 
  "]"}]], "Input",
 CellChangeTimes->{{3.59492488658932*^9, 3.5949248956597137`*^9}, {
  3.594924927011917*^9, 3.594924933402796*^9}, {3.594925079520697*^9, 
  3.594925080610795*^9}}],

Cell[BoxData[
 RowBox[{"ContourPlot", "[", 
  RowBox[{
   RowBox[{"pCO2", "[", 
    RowBox[{"pH", ",", "HCO3", ",", "KbyInitial"}], "]"}], ",", 
   RowBox[{"{", 
    RowBox[{"pH", ",", "6.8", ",", "8"}], "}"}], ",", 
   RowBox[{"{", 
    RowBox[{"HCO3", ",", "0", ",", "100"}], "}"}], ",", "\[IndentingNewLine]", 
   RowBox[{"Contours", "\[Rule]", 
    RowBox[{"{", 
     RowBox[{"20", ",", "40", ",", "80"}], "}"}]}]}], "\[IndentingNewLine]", 
  "]"}]], "Input",
 CellChangeTimes->{{3.588011703454999*^9, 3.5880117174087048`*^9}, {
  3.5880117501903267`*^9, 3.588011883386302*^9}, {3.588012489020569*^9, 
  3.588012525930511*^9}, {3.58802796882439*^9, 3.5880279848488283`*^9}, {
  3.5880303452699127`*^9, 3.5880303962599163`*^9}, {3.58803326679*^9, 
  3.588033269893515*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"J", "[", 
    RowBox[{"CO2_", ",", "H_", ",", "HCO3_", ",", "K_"}], "]"}], ":=", 
   "\[IndentingNewLine]", 
   RowBox[{"With", "[", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"{", 
      RowBox[{
       RowBox[{"kb", "=", "1"}], ",", 
       RowBox[{"kf", "=", "K"}]}], "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"kf", " ", "CO2"}], "-", 
      RowBox[{"kb", " ", "H", " ", "HCO3"}]}]}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588018786296715*^9, 3.588018834936934*^9}, {
  3.58803064993417*^9, 3.588030702244219*^9}, {3.588030736556336*^9, 
  3.5880307392600393`*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"s2", "[", 
    RowBox[{
    "initialHmolar_", ",", "initialCO2molar_", ",", "initialHCO3molar_"}], 
    "]"}], ":=", 
   RowBox[{"NDSolve", "[", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"{", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{
        RowBox[{
         RowBox[{"H", "'"}], "[", "t", "]"}], "\[Equal]", 
        RowBox[{"J", "[", 
         RowBox[{
          RowBox[{"CO2", "[", "t", "]"}], ",", 
          RowBox[{"H", "[", "t", "]"}], ",", 
          RowBox[{"HCO3", "[", "t", "]"}], ",", "KfromTextbook"}], "]"}]}], 
       ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{
         RowBox[{"HCO3", "'"}], "[", "t", "]"}], "==", 
        RowBox[{"J", "[", 
         RowBox[{
          RowBox[{"CO2", "[", "t", "]"}], ",", 
          RowBox[{"H", "[", "t", "]"}], ",", 
          RowBox[{"HCO3", "[", "t", "]"}], ",", "KfromTextbook"}], "]"}]}], 
       ",", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{
         RowBox[{"CO2", "'"}], "[", "t", "]"}], "\[Equal]", "0"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"H", "[", "0", "]"}], "\[Equal]", "initialHmolar"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"CO2", "[", "0", "]"}], "\[Equal]", "initialCO2molar"}], ",", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"HCO3", "[", "0", "]"}], "\[Equal]", "initialHCO3molar"}]}], 
      "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
     RowBox[{"{", 
      RowBox[{"H", ",", "HCO3", ",", "CO2"}], "}"}], ",", 
     RowBox[{"{", 
      RowBox[{"t", ",", "0", ",", "200"}], "}"}]}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.588018715475564*^9, 3.5880187162902117`*^9}, {
   3.588018840234191*^9, 3.588018998732294*^9}, {3.588019038114986*^9, 
   3.5880191392578297`*^9}, {3.58801919229058*^9, 3.5880192037189703`*^9}, {
   3.5880192708295116`*^9, 3.5880193124369717`*^9}, 3.588019393691187*^9, {
   3.588019780866252*^9, 3.588019781165984*^9}, {3.5880267892763033`*^9, 
   3.588026813484517*^9}, {3.588027037873416*^9, 3.5880270428576*^9}, {
   3.588027279146137*^9, 3.588027321720139*^9}, {3.5880273575433826`*^9, 
   3.5880273907936583`*^9}, {3.588027420862603*^9, 3.5880274750777607`*^9}, {
   3.5880280434626217`*^9, 3.5880280573032427`*^9}, {3.5880291201567917`*^9, 
   3.588029129520361*^9}, {3.588029918088847*^9, 3.5880299189117603`*^9}, {
   3.588030715718298*^9, 3.588030723876318*^9}, {3.5949252432218523`*^9, 
   3.594925272156485*^9}, {3.594926658893195*^9, 3.594926659116704*^9}}],

Cell[BoxData[
 RowBox[{
  RowBox[{"Manipulate", "[", 
   RowBox[{
    RowBox[{"{", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"Plot", "[", 
       RowBox[{
        RowBox[{"Evaluate", "[", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"-", 
            RowBox[{"Log10", "[", 
             RowBox[{"H", "[", "t", "]"}], "]"}]}], "}"}], "/.", 
          RowBox[{"(", 
           RowBox[{"s2", "[", 
            RowBox[{
             RowBox[{"Hmolar", "[", "initialPh", "]"}], ",", 
             RowBox[{"CO2molar", "[", "initialCO2mmHg", "]"}], ",", 
             "initialHCO3molar"}], "]"}], ")"}]}], "]"}], ",", 
        RowBox[{"{", 
         RowBox[{"t", ",", "0", ",", "200"}], "}"}], ",", 
        RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"Plot", "[", 
       RowBox[{
        RowBox[{"Evaluate", "[", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"1000", " ", "solubilityMolarPerMmhg", " ", 
            RowBox[{"CO2", "[", "t", "]"}]}], "}"}], "/.", 
          RowBox[{"s2", "[", 
           RowBox[{
            RowBox[{"Hmolar", "[", "initialPh", "]"}], ",", 
            RowBox[{"CO2molar", "[", "initialCO2mmHg", "]"}], ",", 
            "initialHCO3molar"}], "]"}]}], "]"}], ",", 
        RowBox[{"{", 
         RowBox[{"t", ",", "0", ",", "200"}], "}"}], ",", 
        RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}], ",", 
      "\[IndentingNewLine]", 
      RowBox[{"Plot", "[", 
       RowBox[{
        RowBox[{"Evaluate", "[", 
         RowBox[{
          RowBox[{"{", 
           RowBox[{"1000", " ", 
            RowBox[{"HCO3", "[", "t", "]"}]}], "}"}], "/.", 
          RowBox[{"s2", "[", 
           RowBox[{
            RowBox[{"Hmolar", "[", "initialPh", "]"}], ",", 
            RowBox[{"CO2molar", "[", "initialCO2mmHg", "]"}], ",", 
            "initialHCO3molar"}], "]"}]}], "]"}], ",", 
        RowBox[{"{", 
         RowBox[{"t", ",", "0", ",", "200"}], "}"}], ",", 
        RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]}], 
     "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{"initialPh", ",", "7.4"}], "}"}], ",", " ", "7.0", ",", " ", 
      "7.8"}], "}"}], ",", "\[IndentingNewLine]", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{"initialCO2mmHg", ",", "40"}], "}"}], ",", " ", "20", ",", " ",
       "80"}], "}"}]}], "\[IndentingNewLine]", "]"}], 
  "\[IndentingNewLine]"}]], "Input",
 CellChangeTimes->{{3.5880193595553627`*^9, 3.588019419808826*^9}, {
   3.588019586814019*^9, 3.588019640555421*^9}, {3.588019692218618*^9, 
   3.588019694042286*^9}, {3.588019750250059*^9, 3.588019813783346*^9}, {
   3.5880299242152042`*^9, 3.5880299245991173`*^9}, 3.588033297268264*^9, {
   3.594925306922489*^9, 3.59492536201825*^9}, {3.59492539337101*^9, 
   3.5949253975291853`*^9}, {3.594926391490402*^9, 3.594926459456328*^9}, {
   3.594926522813073*^9, 3.5949265682890987`*^9}, 3.594926628374145*^9, {
   3.59492666306857*^9, 3.594926668628605*^9}, {3.594926733742449*^9, 
   3.5949267619144793`*^9}, {3.594927034677702*^9, 3.594927065614521*^9}, {
   3.594927117626059*^9, 3.5949271438758173`*^9}, {3.594927183921032*^9, 
   3.5949271912485037`*^9}}],

Cell[BoxData[""], "Input",
 CellChangeTimes->{{3.5880193595553627`*^9, 3.588019419808826*^9}, {
   3.588019586814019*^9, 3.588019640555421*^9}, {3.588019692218618*^9, 
   3.588019694042286*^9}, {3.588019750250059*^9, 3.58801983773449*^9}, {
   3.588029927447898*^9, 3.588029928206938*^9}, {3.5880332289800587`*^9, 
   3.5880332302508907`*^9}, 3.594925531727243*^9, 3.594926407458445*^9}],

Cell[BoxData[""], "Input",
 CellChangeTimes->{{3.5880193595553627`*^9, 3.588019419808826*^9}, {
   3.588019586814019*^9, 3.588019640555421*^9}, {3.588019692218618*^9, 
   3.588019694042286*^9}, {3.588019750250059*^9, 3.5880198711418*^9}, {
   3.588029931103701*^9, 3.5880299319987698`*^9}, 3.594925536183242*^9, 
   3.5949264171135073`*^9}]
},
WindowSize->{1440, 852},
WindowMargins->{{0, Automatic}, {Automatic, 0}},
FrontEndVersion->"9.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (January 25, \
2013)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[557, 20, 143, 3, 28, "Input"],
Cell[703, 25, 504, 11, 33, "Input"],
Cell[1210, 38, 149, 3, 28, "Input"],
Cell[1362, 43, 208, 4, 28, "Input"],
Cell[1573, 49, 576, 12, 49, "Input"],
Cell[2152, 63, 147, 3, 28, "Input"],
Cell[2302, 68, 348, 7, 32, "Input"],
Cell[2653, 77, 200, 4, 28, "Input"],
Cell[2856, 83, 328, 8, 51, "Input"],
Cell[3187, 93, 594, 14, 53, "Input"],
Cell[3784, 109, 187, 4, 28, "Input"],
Cell[3974, 115, 361, 8, 49, "Input"],
Cell[4338, 125, 241, 6, 28, "Input"],
Cell[4582, 133, 884, 18, 63, "Input"],
Cell[5469, 153, 638, 14, 80, "Input"],
Cell[6110, 169, 776, 17, 63, "Input"],
Cell[6889, 188, 654, 17, 80, "Input"],
Cell[7546, 207, 2582, 57, 182, "Input"],
Cell[10131, 266, 3285, 77, 165, "Input"],
Cell[13419, 345, 387, 5, 28, "Input"],
Cell[13809, 352, 340, 5, 28, "Input"]
}
]
*)

(* End of internal cache information *)